<?php 
    class Student_leave_model extends CI_Model{

        function __construct(){
            parent::__construct();
        }

        /**
         * 获取签到数据
         * @param  [type] $date      [description]
         * @param  [type] $school_id [description]
         * @return [type]            [description]
         */
        function get_leave_list($school_id, $limit = 0, $offset = 10, $conditions = array()){
            $where = "lea.school_id='{$school_id}'";
            if(!empty($conditions['student'])){
                $where .= " AND stu.name LIKE '%{$conditions['student']}%' ";
            }
            $sql = "select SQL_CALC_FOUND_ROWS lea.*,stu.name as student_name,cla.class_name,plan.class_time,campus.name as campus_name from {$this->db->dbprefix}o2o_student_leave lea
                left join {$this->db->dbprefix}o2o_student stu on stu.student_id = lea.student_id
                left join {$this->db->dbprefix}o2o_class cla on cla.id = lea.class_id
                left join {$this->db->dbprefix}o2o_school_campus campus on campus.id=cla.campus 
                left join {$this->db->dbprefix}o2o_class_plan plan on plan.id = lea.class_plan_id
                where $where LIMIT $limit, $offset";
            $result = $this->db->query($sql)->result_array();
            $row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
            return array("count" => $row_num['row_num'], "result" => $result);
        }

        /**
         * 添加请假记录
         * @param [type] $school_id [description]
         * @param [type] $leave      [description]
         */
        function add_leave($school_id,$leave){
            $leave['school_id'] = $school_id;
            $leave['class_plan_id'] = 0;
            $leave['add_time'] = time();
            return $this->db->insert('o2o_student_leave',$leave);
        }



        
    }